#ifndef SERVUNO_H
#define SERVUNO_H

#include <QObject>
#include <QtScript>
#include <QFile>
#include <QThread>

namespace Aurasim {
namespace jservuno {

static const int MAX_PINS = 20;
bool checkRange(const int &pin);

class ServUno : public QObject
{
    Q_OBJECT
public:
    explicit ServUno(QObject *parent = nullptr);
    ~ServUno() override;
    static ServUno* instance() { static ServUno uno; return &uno; }

    void loadSketch(const QString& file);
    void startSim();
    void stopSim();

    int digVal(const int& pin) const;
    int anaVal(const int& pin) const;
    int pinMode(const int& pin) const;
    int signalType(const int& pin) const;
    void setDigVal(const int& pin, const int& val);
    void setAnaVal(const int& pin, const int& val);
    void setPinMode(const int& pin, const int& mode);
    void setSignalType(const int& pin, const int& type);

signals:

public slots:

private:
    int mDigVals[MAX_PINS];
    int mAnaVals[MAX_PINS];
    int mPinModes[MAX_PINS];
    int mSignalTypes[MAX_PINS]; // 0 for digital signal, 1 for ananlog signal
    QString mSketchFile;
    QScriptEngine* mEngine;
    QThread* mSimThread;
    QString mSoureCode;
};

ServUno* board();

}
}


#endif // SERVUNO_H
